package com.lws.omapicompat.simalliance

import com.lws.omapicompat.ChannelCompat
import com.lws.omapicompat.ReaderCompat
import com.lws.omapicompat.SessionCompat
import org.simalliance.openmobileapi.Session

class SessionOld(private val readerOld: ReaderOld, private val session: Session) : SessionCompat {

    override fun close() {
        session.close()
    }

    override fun closeChannels() {
        session.closeChannels()
    }

    override fun getATR(): ByteArray? {
        return session.atr
    }

    override fun getReader(): ReaderCompat {
        return readerOld
    }

    override fun isClosed(): Boolean {
        return session.isClosed
    }

    override fun openBasicChannel(aid: ByteArray?, p2: Byte): ChannelCompat? {
        val channel = session.openBasicChannel(aid, p2) ?: return null
        return ChannelOld(this, channel)
    }

    override fun openBasicChannel(aid: ByteArray?): ChannelCompat? {
        return openBasicChannel(aid, 0.toByte())
    }

    override fun openLogicalChannel(aid: ByteArray?, p2: Byte): ChannelCompat? {
        val channel = session.openLogicalChannel(aid, p2) ?: return null
        return ChannelOld(this, channel)
    }

    override fun openLogicalChannel(aid: ByteArray?): ChannelCompat? {
        return openLogicalChannel(aid, 0.toByte())
    }
}